'''设计一个培训机构管理系统，有总部、分校，有学员、老师、员工，实现具体如下需求：

有多个课程，课程要有定价

有多个班级，班级跟课程有关联

有多个学生，学生报名班级，交这个班级对应的课程的费用

有多个老师，可以分布在不同校区，上不同班级的课

有多个员工，可以分布在不同校区在总部可以统计各校区的账户余额、员工人数、学员人数

学生可以转校、退学'''
import time


class School:
    def __init__(self, name, address):
        self.name, self.address = name, address
        self.__staff = []  # 学校员工
        self.branches = {}  # 下属校区
        self.__bank_account_balance = 0  # 学校金额

    def show_balance(self):  # 显示校区地址
        print('初始化校区：[%s]，地址：%s' % (self.name, self.address))

    def conut_balance(self):  # 计算学校总金额
        balance = self.__bank_account_balance
        for i, val in self.branches.items():
            balance += val.__bank_account_balance
        print("Total balance:%s" % balance)
        self.__bank_account_balance = balance

    def in_tuition(self, price, from_obj, purpose):  # 学校收账记录
        self.__bank_account_balance += price
        print("%s,校区[%s]收到[%s]转账[%s],交费原因[%s]..." % (time.strftime("%Y-%m-%d %H:%M:%S"),
                                                     self.name, from_obj.name, price, purpose))

    def show_balance(self):  # 各校区金额
        print('[%s]账户金额:%s' % (self.name, self.__bank_account_balance))

    def new_staff(self, staff_obj):  # 添加新员工
        self.__staff.append(staff_obj)

    def staff_num(self):  # 显示各校区员工人数和总人数
        sta_num = len(self.__staff)
        for i in self.branches:
            sta_num += self.branches[i].staff_num()
        print('[%s]总员工人数：%d' % (self.name, len(self.__staff)))
        if self.name == '小猿圈北京总部':
            print('公司总员工:%s' % sta_num)
        return sta_num


class BranchSchool(School):  # 分校继承学校
    def __init__(self, name, address, headquater):  # 学校基础上加了分校自己的名字和地址
        super(BranchSchool, self).__init__(name, address)
        self.headquater = headquater
        self.headquater.branches[self.name] = self


class Class:  # 班级
    def __init__(self, course_obj, school_obj, class_num, time):
        self.class_num, self.course_obj, self.school_obj = class_num, course_obj, school_obj
        self.time, self.stu = time, []  # self.stu用来添加每个班级的学员信息 和添加员工一个道理

    def print_course_init(self):  # 开班开课信息
        print('校区[%s]开设了[%s]课程第[%s]班，开班时间[%s]' %
              (self.school_obj.name, self.course_obj.name, self.class_num, self.time))

    def get_class_name(self):  # 得到开班的信息
        return "%s-%s-s%s期" % (self.school_obj.name, self.course_obj.name, self.class_num)

    def drop_out(self, stu_obj):  # 学员退学进行记录
        self.stu.remove(stu_obj)
        print('学员[%s]从[%s]退学了' % (stu_obj.name, self.get_class_name()))


class Course:  # 课程
    def __init__(self, name, price, outline):
        self.name, self.price, self.outline = name, price, outline


class Student:  # 学生
    def __init__(self, name, age, degree, class_obj, balance):  # 信息进行初始化
        self.name, self.age, self.degree, self.class_obj, self.balance = name, age, degree, class_obj, balance
        self.class_obj.stu.append(self)

    def pay_tuition(self):  # 支付学费 扣除金额  应用学校收账函数记录进学校金额
        self.balance -= self.class_obj.course_obj.price
        self.class_obj.school_obj.in_tuition(self.class_obj.course_obj.price, self,
                                             "交%s学费" % self.class_obj.get_class_name())


class Staff:  # 员工信息
    def __init__(self, name, age, position, salary, dept, school_obj, time):  # 初始化员工信息
        self.name, self.age, self.position, self.salary = name, age, position, salary
        self.dept, self.school_obj, self.time = dept, school_obj, time
        self.school_obj.new_staff(self)

    def print_init(self):  # 显示员工信息
        print('校区[%s]的[%s]部门在[%s]入职一位新同事[%s]，职位是[%s]' %
              (self.school_obj.name, self.dept, self.time, self.name, self.position))


class Teacher(Staff):  # 老师继承员工
    def teaching(self):
        pass


headquater = School("小猿圈北京总部", "北京长安街1号")  # 初始化校区
bj1 = BranchSchool("小猿圈北京分校", "北京昌平流沙河汇德商厦401", headquater)
sh1 = BranchSchool("小猿圈上海1分校", "上海张江科技园", headquater)
sh2 = BranchSchool("小猿圈上海2分校", "上海虹桥火车站", headquater)
sz1 = BranchSchool("深圳南山大学城分校", "深圳南山大学城桃李创业园", headquater)
headquater.show_balance()  # 显示校区地址
bj1.show_balance()
sh1.show_balance()
sh2.show_balance()
sz1.show_balance()
staff1 = Staff("Alex", 26, "CEO", 60000, "总经办", headquater, "2015-05-22")  # 初始化员工
staff2 = Staff("周小月", 23, "HR", 6000, "HR", headquater, "2017-03-12")
t1 = Teacher("Mjj", 27, "前端开发讲师", 30000, "教研部", bj1, "2018-02-26")
t2 = Teacher("银角大王", 27, "Python讲师", 45000, "教研部", sz1, "2016-07-14")
t3 = Teacher("苑日天", 23, "Java讲师", 40000, "教研部", sh1, "2018-07-14")
staff1.print_init()  # 显示员工信息
staff2.print_init()
t1.print_init()
t2.print_init()
t3.print_init()
py_course = Course("Python开发", 21800, "本科")  # 初始化课程
linux_course = Course("Linux云计算运维", 19800, "专科")
go_course = Course("GO开发", 9800, "本科")
class1 = Class(py_course, bj1, 21, '2019-05-06')  # 初始化班级
class2 = Class(linux_course, sz1, 4, '2019-04-16')
class3 = Class(go_course, sh1, 11, '2019-06-21')
class1.print_course_init()  # 显示开课信息
class2.print_course_init()
class3.print_course_init()
stu1 = Student("blackgirl", 22, "本科", class1, 30000)  # 初始化学员
stu2 = Student("李晓虎", 23, "专科", class2, 25000)
stu3 = Student("林爱根", 26, "本科", class3, 13000)
stu4 = Student("刘清蒸", 21, "本科", class3, 10000)
stu5 = Student("海底捞哥", 21, "专科", class1, 20000)
for i in (stu1, stu2, stu3, stu4):  # 支付学费
    i.pay_tuition()
for i in class3.stu:  # 打印某班级学生信息
    print(i.name + ',班级:' + i.class_obj.school_obj.name + '-' + i.class_obj.course_obj.name + '-s' + str(
        i.class_obj.class_num) + '期')
bj1.show_balance()  # 各校区财务金额
sh1.show_balance()
sh2.show_balance()
sz1.show_balance()
headquater.conut_balance()  # 总金额
headquater.staff_num()  # 各校区人员数和总人数
stu5.class_obj.drop_out(stu5)  # stu5退学

